<template>
    <el-container>
        <el-container class="is-vertical">
            <div class="panel-search-box">
                <div class="panel-search">
                    <el-input v-model="search.userName" placeholder="学员姓名" clearable  class="w165"></el-input>
                    <el-input v-model="search.courseName" placeholder="课程名称" clearable  class="w165"></el-input>
                    <el-input v-model="search.articleName" placeholder="文章名称" clearable  class="w165"></el-input>
                    <el-date-picker v-model="search.submitTime" type="datetimerange" value-format="YYYY-MM-DD HH:mm" format="YYYY-MM-DD HH:mm"
							range-separator="至" start-placeholder="答题开始时间" end-placeholder="答题结束时间" class="sDateSelect" style="margin-left:10px;width:350px;"></el-date-picker>
                    <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
                </div>
            </div>
            <el-main class="nopadding" style="min-height:500px;">
                <scDialogTable ref="table" :apiObj="$API.articleExercise.log.list" :params="search" remoteSort @dataChange="dataChange" :exportData="exportData" :formatExportData="formatExportData" :height="500">
                    <el-table-column label="序号" prop="index" width="70" align="left"></el-table-column>
                    <el-table-column label="学员" prop="user" align="center" show-overflow-tooltip>
                        <template #default="scope">
                            {{scope.row.user ? scope.row.user.name : ''}}
                        </template>
                    </el-table-column>
                    <el-table-column label="课程名称" prop="course" width="120" align="center">
                        <template #default="scope">
                            {{scope.row.course ? scope.row.course.name : ''}}
                        </template>
                    </el-table-column>
                    <el-table-column label="文章关卡" prop="article" width="120" align="center" show-overflow-tooltip>
                        <template #default="scope">
                            {{scope.row.article ? scope.row.article.name : ''}}
                        </template>
                    </el-table-column>
                    <el-table-column label="总题目数" prop="totalNumber" width="100" align="center"></el-table-column>
                    <el-table-column label="正确数" prop="rightNumber" width="100" align="center"></el-table-column>
                    <el-table-column label="错误数" prop="wrongNumber" width="100" align="center"></el-table-column>
                    <el-table-column label="正确率(%)" prop="rightRate" width="100" align="center"></el-table-column>
                    <el-table-column label="答题用时" prop="useTime" width="100" align="center"></el-table-column>
                    <el-table-column label="答题时间" width="150" align="center">
                        <template #default="scope">
                            <span>{{ scope.row.submitTime }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="操作" fixed="right" align="center" width="200">
                        <template #default="scope">
                            <el-button type="text" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button>
                        </template>
                    </el-table-column>
                </scDialogTable>
            </el-main>
        </el-container>
    </el-container>


    <detail-dialog v-if="dialog.detail" ref="detailDialog" @closed="dialog.detail=false"></detail-dialog>

</template>

<script>
import detailDialog from '../detail.vue'
export default {
    props: {
        exercise: {type: Object, default: null},
    },
    components: {
        detailDialog,
    },
    data() {
        return {
            dialog: {
                detail: false,
            },
            search: {
                isTeach: 0,
                exerciseId: 0
            },
            exportData: {
                header: ['学员', '课程名称', '文章关卡', '总题目数', '正确数', '错误数', '正确率(%)', '答题用时', '答题时间'],
                column: ['userName', 'courseName', 'articleName', 'totalNumber', 'rightNumber', 'wrongNumber', 'rightRate', 'useTime', 'submitTime'],
                filename: '阅读理解答题记录列表',
                formatData: true
            },
        }
    },
    mounted() {
        if (this.exercise) {
            this.search.exerciseId = this.exercise.id
        }
    },
    methods: {
        dataChange(res, tableData) {
			let total = res.data.total
            let perPage = res.data.perPage
            let page = (this.$refs.table && this.$refs.table.currentPage) || 1
            tableData.forEach((item, index) => {
				item.index = page * perPage + index - perPage + 1
            })
        },
        //查看
        table_show(row) {
            this.dialog.detail = true
			this.$nextTick(() => {
				this.$refs.detailDialog.open().setData(row)
			})
        },
        exportHander() {
			this.$refs.table.exportHander(this.search)
		},
		formatExportData(item) {
            item.userName = item.user ? item.user.name : ''
            item.courseName = item.course ? item.course.name : ''
            item.articleName = item.article ? item.article.name : ''
            return item
        },
        // 搜索
        upsearch() {
            this.$refs.table.upData(this.search)
        },
        //本地更新数据
        handleSuccess() {
            this.$refs.table.refresh()
        }
    }
}
</script>

<style>
.position {
    display: flex;
    align-items: center;
}
.position-item {
    margin-right: 5px;
}
.position-item:last-child {
    margin-right: 0;
}
</style>
